package com.winit.deploy.factory;

import com.winit.core.task.ChainBaseTask;
import com.winit.core.task.Task;
import com.winit.core.task.TaskNode;
import com.winit.deploy.task.tomcatTask.SleepTask;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wangjian on 16/8/16.
 * 测试用
 */
public class DeployTaskFactoryTest{

    /**
     * 多任务
     * @return
     */
    public ChainBaseTask createAutoDeployTask(String taskId,ChainBaseTask.TaskHandler handler,boolean isConfirm){
        SleepTask a = new SleepTask(taskId,20);
        TaskNode na = new TaskNode(a,isConfirm);

        List<TaskNode> taskNodeList = new ArrayList<>();
        taskNodeList.add(na);
        taskNodeList.add(na);
        taskNodeList.add(na);
        taskNodeList.add(na);
        taskNodeList.add(na);
        taskNodeList.add(na);

        ChainBaseTask chainBaseTask = new ChainBaseTask(taskId,0,taskNodeList,handler);
        return chainBaseTask;
    }

    public ChainBaseTask createAutoDeployTaskWithError(String taskId,Task task,ChainBaseTask.TaskHandler handler,boolean isConfirm){
        SleepTask a = new SleepTask(taskId,20);

        TaskNode na = new TaskNode(a,isConfirm);
        TaskNode nb = new TaskNode(task,isConfirm);

        List<TaskNode> taskNodeList = new ArrayList<>();
        taskNodeList.add(na);
        taskNodeList.add(na);
        taskNodeList.add(nb);
        taskNodeList.add(na);
        taskNodeList.add(na);
        taskNodeList.add(na);

        ChainBaseTask chainBaseTask = new ChainBaseTask(taskId,0,taskNodeList,handler);
        return chainBaseTask;
    }

    /**
     * 单任务
     * @param taskId
     * @param task
     * @param handler
     * @return
     */
    public ChainBaseTask createChainTaskWithSingleTaskNode(String taskId, Task task
            , ChainBaseTask.TaskHandler handler,boolean isConfirm,Integer index){
        TaskNode na = new TaskNode(task,isConfirm,index);

        List<TaskNode> taskNodeList = new ArrayList<>();
        taskNodeList.add(na);

        ChainBaseTask chainBaseTask = new ChainBaseTask(taskId,0,taskNodeList,handler);
        return chainBaseTask;
    }


}
